********************************************************************************
*
*    PROJECT: MENTORING, EDUCATIONAL PREFERENCES, AND CAREER CHOICE 
*
*    AUTHORS: HAYASHI, KIM, MATSUDA, PHAM
* 
*    DATE: MAY 2025
*
********************************************************************************

/* 
This is a "master" dofile. It declares the directory structure, 
calls all dofiles to create datasets and perform the analysis.

Part 1: Declare directories.
Part 2: Call the dofiles that create the datasets.
Part 3: Call the dofiles that create the tables, figures and other values 
        reported in the paper.

*/
version 17
clear all
capture log close
set varabbrev off
set more off

local tcdate = subinstr("$S_DATE", " ", "", .)
global date "`tcdate'"


********************************************************************************
*
* 					USER-WRITTEN COMMANDS
*
********************************************************************************
cap ado uninstall ftools
net install ftools, from("https://raw.githubusercontent.com/sergiocorreia/ftools/master/src/")
ssc install unique
ssc install spmap
ssc install coefplot
ssc install parmest
ssc install grc1leg2
ssc install matchit
ssc install texsave
ssc install estout
ssc install ivreg2 
ssc install boottest
ssc install mmat2tex
ssc install rwolf 


********************************************************************************
*
*     PART 1: DECLARE DIRECTORIES
*
********************************************************************************
global path ".."

* directory holding do files
gl dofiles "$path/code"

* directory holding data 
gl data "$path/data"

* directory holding original survey datasets
gl raw "$path/data/raw"

* link to test score data 
gl testscoredata "$raw/confidential/testscore.xlsx"

* link to TVET admin data
gl noncbt "$raw/confidential/Non-CBT-trainees.csv.xlsx"
gl cbt "$raw/confidential/CBT-trainees.xlsx"

* link to repeater data 
gl repeat10 "$raw/confidential/X_Repeater_List.xlsx"

* link to TVET admin data
gl noncbt "$raw/confidential/Non-CBT-trainees.csv.xlsx"
gl cbt "$raw/confidential/CBT-trainees.xlsx"

* link to repeater data 
gl repeat12 "$raw/confidential/XII_Repeater_List.xlsx"

* directory holding temporary datasets
gl temp "$path/data/temp"

* directory holding cleaned datasets for the analysis
gl clean "$path/data/clean"

* directory holding randomization results
gl randomization "$path/output/randomization"

* directory holding endline tracking results 
gl endline "$path/output/endline_tracking"

* directory holding mentor report results 
gl mentor_report "$path/output/mentor_report"

* directory holding tables and figures
gl tabfig "$path/output/tables_figures"

* directory holding log files
gl logfile "$path/output/log_files"


/********************************************************************************
*
*     PART 2: CALL THE DOFILES THAT CREATE DATASETS
*
********************************************************************************
* School list (manual)
do "$dofiles/0.1.build_school_list.do"

* Student list (manual)
do "$dofiles/0.2.build_student_list.do"

* Baseline Grade 9-10
do "$dofiles/0.3.build_grade910students_baseline.do"

* Baseline Grade 11-12
do "$dofiles/0.4.build_grade1112students_baseline.do"

/* Randomization at the school level
do "$dofiles/1.1.1.randomization_school_TVET.do"
do "$dofiles/1.1.2.randomization_school_STEM.do"

* Randomization at the student level
do "$dofiles/1.2.1.randomization_student_TVET.do"
do "$dofiles/1.2.2.randomization_student_STEM.do"
do "$dofiles/1.3.randomization_mentor_mentee.do"
*/

* Endline Grade 9-10 
do "$dofiles/2.1.build_grade10_students_endline.do"

* Endline Grade 11-12 
do "$dofiles/2.2.build_grade12_students_endline.do"

* Obtain uniquely matched ID to connect baseline and endline database
do "$dofiles/3.1.matching_grade10_baseline_endline.do"
do "$dofiles/3.2.matching_grade12_baseline_endline.do"

* Generate final mentor dataset for analysis 
do "$dofiles/4.0.1.STEM_mentor.do"
do "$dofiles/4.0.2.TVET_mentor.do"
do "$dofiles/4.0.3.cleaning_mentor_reports.do"

* Generate final mentee dataset for analysis
do "$dofiles/4.1.0.cleaning_grade10.do"
do "$dofiles/4.2.0.cleaning_grade12.do"
*/

********************************************************************************
*
*     PART 3: CALL THE DOFILES THAT CREATE TABLES, FIGURES,
*             AND OTHER VALUES REPORTED IN THE PAPER
*
********************************************************************************

* Replicate the results in Tables & Figures in the manuscript 

do "$dofiles/final_analysis.do"

* Producing the map of study location 

do "$dofiles/map.do"



























